layui.use(['jquery','layer','table','laydate'],function(){
    var $=layui.jquery;
    var layer=layui.layer;
    var table=layui.table;
    var laydate = layui.laydate;

    //绑定时间格式
    laydate.render({
        elem: '#createDate',
        type: 'datetime',
        trigger: 'click'
    })
    getTable('','','','');
    //筛选搜索
    $('#search').on('click',function () {
        var userName = $("input[name=userName]").val();
        var type = $("#type option:selected").val();
        var createDate = $("input[name=createDate]").val();
        getTable(userName,type,createDate);
    })
    //获取表格数据
    function getTable(userName,type,createDate) {
        $.ajax({
            url:'/examine/getExamineLog',
            type:'post',
            dataType:'json',
            data:{'userName':userName,'type':type,'createDate':createDate},
            success:function (data) {
                dataTable(data.data);
            }
        })
    }
    //表格渲染
    function dataTable(data) {
        table.render({
            elem:'#demoTable',
            title:"审核日志",
            data: data,
            toolbar:'#tableHeader',
            limit:10,
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[10,20,30],
                first:'首页',
                last:'尾页',
            },
            cols:[[
                {type:"checkbox",float:"left"},
                {title:"序号",align:'center',templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:"examineType",title:"审核类型",align:'center',templet:function (data) {
                        if(data.examineType==1){
                            return "商品"
                        }else if(data.examineType==2){
                            return "视频"
                        }else if(data.examineType==3){
                            return "微圈"
                        }else if(data.examineType==4){
                            return "用户"
                        }
                    }},
                {field:"type",title:"审核结果",align:'center',templet:function (data) {
                        if(data.type==2){
                            return "审核通过"
                        }else if(data.type==3){
                            return "审核驳回"
                        }
                    }},
                {field:"userName",title:"审核人",align:'center'},
                {field:"createDate",title:"审核时间",align:'center'},
                {field:"remark",title:"备注",align:'center',templet:function (data) {
                        if(data.remark == null||data.remark==""){
                            return "无"
                        }else{
                            return data.remark
                        }
                    }},
                {title:'操作',align:'center',templet:function(data){
                        return '<a onclick="javascript:deleteTable('+ data.auditLogId +');">删除</a>';
                    }}
            ]]
        })
    }
    //删除日志
    deleteTable = function deleteTable(auditLogId){
        layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url: '/examine/deleteAuditLog',
                type: 'post',
                dataType: 'json',
                data: {'id':auditLogId},
                success: function (data) {
                    getTable();
                }
            })
            layer.close(index);
        });
    }
    //刷新
    $('#refresh').click(function () {
        location.reload();
    })
    //返回
    $('#goBack').click(function () {
        parent.tabParentChange(3);
    })
    $(document).click(function () {
        parent.$('.rightMenu').hide();
    });
})